package com.hxd.otc.module.order.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.activity.AdBuyOrderDetailActivity;
import com.hxd.otc.module.order.activity.BuyOrderDetailActivity;
import com.hxd.otc.module.order.bean.AdOrderDetailBean;
import com.hxd.otc.module.order.contract.AdBuyOrderDetailContract;
import com.hxd.otc.module.order.model.AllOrderModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/9 12:02
 * 描  述 :  ${订单完成}
 */
public class AdBuyOrderDetailPresenter extends BasePresenter<AdBuyOrderDetailContract.View> implements AdBuyOrderDetailContract.Presenter {

    AllOrderModel model;

    public AdBuyOrderDetailPresenter(AdBuyOrderDetailContract.View view) {
        super(view);
        model = AllOrderModel.getInstance();
    }

    @Override
    public void doLoadData(String... category) {

        model.getAdOrderDetailData(new BaseObserver<AdOrderDetailBean>() {
            @Override
            public void onNext(String title, AdOrderDetailBean bean) {
                mView.onSetData(bean);
                doShowNoMore();
            }

            @Override
            public void onError(int errType, String errMessage) {
                doShowNoMore();
            }

        }, mView.<BaseBean<AdOrderDetailBean>>bindAutoDispose(), category[0]);

    }

    @Override
    public void doShowNoMore() {
        mView.onHideLoading();
    }

    @Override
    public void confirmCancel(String... category) {
        model.confirmAdCancel(new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.refreshView(AdBuyOrderDetailActivity.CANCLE_CONFIRM_SUCCESS);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose(), category[0]);

    }

    @Override
    public void rejectCancle(String... category) {
        model.rejectAd(new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.refreshView(AdBuyOrderDetailActivity.REJECT_CONFIRM_SUCCESS);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose(), category[0]);
    }

    @Override
    public void paying(String... category) {
        model.paidAdOrder(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {
                mView.refreshView(BuyOrderDetailActivity.PAYIING_SUCCESS);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }


        }, mView.<BaseBean>bindAutoDispose(), category[0]);

    }

}
